package com.lzx.iteam.adapter;

import android.content.Context;
import android.text.Editable;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.SalaryTaxBean;
import com.lzx.iteam.util.StringUtil;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * **********************************
 * User: zhangshuai
 * Date: 2017年 01月 10日
 * Time: 上午11:39
 *
 * @QQ : 1234567890
 * **********************************
 */
public class SalaryWXYJAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<SalaryTaxBean> mDatas;

    public SalaryWXYJAdapter(Context mContext) {
        this.mContext = mContext;

    }

    public void bindData(ArrayList<SalaryTaxBean> mDatas){
        this.mDatas = mDatas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mDatas == null ? 0:mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        convertView = LayoutInflater.from(mContext).inflate(R.layout.wxyj_item_layout,null);
        LinearLayout titleLayout = (LinearLayout) convertView.findViewById(R.id.ll_wxyj_item_title);
        RelativeLayout contentLayout = (RelativeLayout) convertView.findViewById(R.id.rl_wxyj_item_content);
        TextView part = (TextView) convertView.findViewById(R.id.tv_wxyj_item_part);
        TextView name = (TextView) convertView.findViewById(R.id.tv_wxyj_item_name);
        EditText number = (EditText) convertView.findViewById(R.id.ed_wxyj_item_number);
        number.setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_NUMBER_FLAG_DECIMAL);
        TextView percent = (TextView) convertView.findViewById(R.id.tv_wxyj_item_pc);

        SalaryTaxBean bean = mDatas.get(position);
        if (bean.getType() == 0){
            titleLayout.setVisibility(View.VISIBLE);
            contentLayout.setVisibility(View.GONE);
            part.setText(bean.getName());
        }else{
            titleLayout.setVisibility(View.GONE);
            contentLayout.setVisibility(View.VISIBLE);
            name.setText(bean.getName());
            if (bean.getType() == 3){
                number.setText(StringUtil.floatFormat(bean.getTax()));
                percent.setVisibility(View.GONE);
            }else{
                number.setText(StringUtil.floatFormat(Float.parseFloat(bean.getTax()) * 100));
                percent.setVisibility(View.VISIBLE);
            }
        }
        Editable ea = number.getText();
        number.setSelection(ea.length());
        return convertView;
    }


}
